﻿using System.IO;
using System.IO.IsolatedStorage;

namespace SmartNavigation
{
    public static class StorageUtils
    {
        public static void DeleteFolder(this IsolatedStorageFile storage, string path)
        {
            if (!storage.DirectoryExists(path))
                return;
            var folders = storage.GetDirectoryNames(Path.Combine(path, "*.*"));

            foreach (var folder in folders)
            {
                string folderName = path + "/" + folder;
                storage.DeleteFolder(folderName);
            }
            foreach (var file in storage.GetFileNames(Path.Combine(path, "*.*")))
            {
                storage.DeleteFile(Path.Combine(path, file));
            }
            storage.DeleteDirectory(path);
        }

        public static IsolatedStorageFile Storage
        {
            get
            {
                return IsolatedStorageFile.GetUserStoreForApplication();
            }
        }

        public static void CreateDirectoryIfNotExists(string path)
        {
            var storage = Storage;

            if (!storage.DirectoryExists(path))
                storage.CreateDirectory(path);
        }
    }
}